package com.mpush.tools.common;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HashUtil {

	private static final Logger LOGGER = LoggerFactory.getLogger(HashUtil.class);

	private HashUtil() {

	}

	public static String sha1(String text) {
		MessageDigest digest;
		try {
			digest = MessageDigest.getInstance("SHA-1");
		} catch (NoSuchAlgorithmException e) {
			LOGGER.error("sha1签名错误", e);
			return null;
		}
		digest.update(text.getBytes());
		byte messageDigest[] = digest.digest();
		return Hex.encodeHexString(messageDigest);
	}
}
